package com.itheima.pinda.web.truck;


import com.itheima.pinda.DTO.truck.TruckLicenseDto;
import com.itheima.pinda.entity.truck.PdTruckLicense;
import com.itheima.pinda.mapstruct.TruckDTO2Entity;
import com.itheima.pinda.service.PdTruckLicenseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;

/**
 * 车辆行驶证信息管理
 *
 * @author llhuang10
 * @date 2021/10/2 16:31
 */
@Slf4j
@Validated
@Api(tags = "车辆行驶证信息管理")
@RestController
@RequestMapping("base/truck/license")
public class TruckLicenseController {

    @Resource
    private PdTruckLicenseService pdTruckLicenseService;

    @Resource
    private TruckDTO2Entity truckDTO2Entity;

    /**
     * 保存车辆行驶证信息
     *
     * @param dto 车辆行驶证信息
     * @return 车辆行驶证信息
     */
    @PostMapping
    @ApiOperation("保存车辆行驶证信息")
    public TruckLicenseDto saveTruckLicense(@RequestBody TruckLicenseDto dto) {
        return pdTruckLicenseService.saveTruckLicense(dto);
    }

    /**
     * 根据id获取车辆行驶证详情
     *
     * @param id 车辆行驶证id
     * @return 车辆行驶证信息
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id获取车辆行驶证详情")
    public TruckLicenseDto fineById(@NotBlank(message = "车辆行驶证id不能为空")
                                    @PathVariable(name = "id") String id) {
        PdTruckLicense pdTruckLicense = pdTruckLicenseService.getById(id);
        return truckDTO2Entity.conver(pdTruckLicense);
    }
}
